{{ define "content" }}
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>{{ i18n "Bind" . }}</h2>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <form class="form-horizontal form-label-left" role="form" method="post" id="send-yaml" novalidate>
                    {{ if .types }}
                    <div class="item form-group">
                        <label for="type" class="control-label col-md-3 col-sm-3 col-xs-12">{{ i18n "Type" . }}</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select id="profile" name="profile" class="form-control select2">
                            {{ range $name, $type := .types }}
                                <option value="{{ $name }}">{{ $name }}</option>
                            {{ end }}
                            </select>
                        </div>
                    </div>
                    {{ end }}
                    <div class="item form-group">
                        <label for="yaml" class="control-label col-md-3 col-sm-3 col-xs-12">
                            {{ i18n "YAML" . }} <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <textarea class="form-control resizable_textarea" rows="10" name="yaml" id="yaml" required="required">{{ .yaml }}</textarea>
                        </div>
                    </div>
                    <div class="ln_solid"></div>
                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                            {{ if .bindId }}
                            <button id="send" type="submit" class="btn btn-warning">{{ i18n "Update" . }}</button>
                            {{ else }}
                            <button id="send" type="submit" class="btn btn-success">{{ i18n "Create" . }}</button>
                            {{ end }}
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{{ end }}

{{ define "js" }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/validator/js/validator.min.js" false) }}

    {{ if .types }}
    <script type="application/javascript">
        $(document).ready(function () {
            var
                s = $('#profile'),
                f = $('#send-yaml');

            var load = function () {
                $.ajax({
                    type: 'GET',
                    url: f.prop('action'),
                    data: {
                        type: s.val(),
                    },
                    success: function (r) {
                        $('#yaml').val(r);
                    }
                });
            };

            s.change(load);
            load();
        });
    </script>
    {{ end }}
{{ end }}
